package com.rbac.web.model;

import java.util.Arrays;
import java.util.Optional;
import lombok.Getter;

/**
 * @author gengaoliu
 */
@Getter
public enum PermissionAction {
  /**
   * 权限
   */
  GET("get"),
  POST("post"),
  PUT("put"),
  DELETE("delete"),
  HEAD("head"),
  OPTIONS("options"),
  PATCH("patch");
  private final String value;

  PermissionAction(String value) {
    this.value = value;
  }

  public static PermissionAction getByValue(String value) {
    return Arrays.stream(PermissionAction.values())
        .filter(action -> action.getValue().equals(value.toLowerCase()))
        .findFirst()
        .orElse(null);
  }

  public static String getActionValue(PermissionAction action) {
    return Optional.ofNullable(action).map(PermissionAction::getValue).orElse("");
  }
}
